﻿using System;
using System.Windows.Forms;

namespace SimpleNotify.Client.Views
{
    public partial class StatusView : Form, IStatusView
    {
        private StatusViewPresenter _presenter;

        public StatusView(ClientLibrary.Client wrapper)
        {
            InitializeComponent();
            _presenter = new StatusViewPresenter(this, wrapper);
        }

        #region Private Methods

        private void StatusView_Shown(object sender, EventArgs e)
        {
            _presenter.OnViewReady();
        }

        private void link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            _presenter.OnLinkClicked();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            _presenter.OnViewClose();
        }

        #endregion

        #region Interface Members

        public void InvokeMethod(MethodInvoker methodInvoker)
        {
            if (this.IsHandleCreated)
            {
                this.Invoke(methodInvoker);
            }
        }

        public void SetConnectionActive()
        {
            lblNotConnected.Visible = false;
            panelConnected.Visible = true;
            pbAnimation.Image = Properties.Resources.StatusActive;
        }

        public void SetConnectionInactive()
        {
            lblNotConnected.Visible = true;
            panelConnected.Visible = false;
            pbAnimation.Image = Properties.Resources.Inactive;
        }

        public void UpdateLabels(string clientHost, string serviceHost, string version)
        {
            lblVersion.Text = version;
            lblClient.Text = clientHost;
            lblServer.Text = serviceHost;
        }

        #endregion
    }
}
